tests: Add a gjs-based test
authorColin Walters <walters@verbum.org>
Wed, 18 Sep 2013 16:01:46 +0000 (12:01 -0400)
committerColin Walters <walters@verbum.org>
Wed, 18 Sep 2013 16:02:12 +0000 (12:02 -0400)
This covers introspection, and in general is a much better way to get
API coverage tests.

Makefile-tests.am
configure.ac
tests/test-core.js [new file with mode: 0644]

index 144dac9ce780ffa0167e6d223b653b6afe41d696..82382da715ae6178930523d42fe99aa8d2cd1ad4 100644 (file)
@@ -47,7 +47,19 @@ insttest_DATA = tests/archive-test.sh \
         echo 'Output=TAP' >> $@.tmp; \
         mv $@.tmp $@)
 
+%.test: tests/%.js Makefile
+       $(AM_V_GEN) (echo '[Test]' > $@.tmp; \
+        echo 'Exec=$(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \
+        echo 'Type=session' >> $@.tmp; \
+        mv $@.tmp $@)
+
 testmetadir = $(datadir)/installed-tests/$(PACKAGE)
 testmeta_DATA = $(testfiles:=.test)
 
+if BUILDOPT_GJS
+insttest_SCRIPTS += tests/test-core.js
+testmeta_DATA += test-core.test
+endif
+
+
 endif
index 74df7b4acc1db5d156c7d3c1ac8713c30778110e..d28987615aa3fc87c034ebd238587aa6cb7a12d1 100644 (file)
@@ -128,6 +128,15 @@ AS_IF([test "x$with_dracut" = "xyes"], [
   ])
 ])
 
+dnl for tests
+AC_PATH_PROG(GJS, [gjs])
+if test -n "$GJS"; then
+  have_gjs=yes
+else
+  have_gjs=no
+fi
+AM_CONDITIONAL(BUILDOPT_GJS, test x$have_gjs = xyes)
+
 AC_CONFIG_FILES([
 Makefile
 embedded-dependencies/Makefile
@@ -146,6 +155,7 @@ echo "
     libsoup (retrieve remote HTTP repositories):  $with_soup
     libarchive (parse tar files directly):        $with_libarchive
     documentation:                                $enable_gtk_doc
+    gjs-based tests:                              $have_gjs
     dracut:                                       $with_dracut"
 AS_IF([test "x$with_dracut" = "xyes"], [
     echo "    systemd unit dir:                             $with_systemdsystemunitdir"
diff --git a/tests/test-core.js b/tests/test-core.js
new file mode 100644 (file)
index 0000000..44c5d1e
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/env gjs
+
+const Gio = imports.gi.Gio;
+const OSTree = imports.gi.OSTree;
+
+function assertEquals(a, b) {
+    if (a != b)
+       throw new Error("assertion failed " + JSON.stringify(a) + " == " + JSON.stringify(b));
+}
+
+let testDataDir = Gio.File.new_for_path('test-data');
+testDataDir.make_directory(null);
+testDataDir.get_child('some-file').replace_contents("hello world!", null, false, 0, null);
+
+let repoPath = Gio.File.new_for_path('repo');
+let repo = OSTree.Repo.new(repoPath);
+repo.create(OSTree.RepoMode.ARCHIVE_Z2, null);
+
+repo.open(null);
+
+assertEquals(repo.get_mode(), OSTree.RepoMode.ARCHIVE_Z2);
+
+repo.prepare_transaction(null);
+
+let mtree = OSTree.MutableTree.new();
+repo.write_directory_to_mtree(testDataDir, mtree, null, null);
+let [,dirTree] = repo.write_mtree(mtree, null);
+let [,commit] = repo.write_commit(null, 'Some subject', 'Some body', null, dirTree, null);
+print("commit => " + commit);
+
+repo.commit_transaction(null, null);
+
+let [,root,checksum] = repo.read_commit(commit, null);
+let child = root.get_child('some-file');
+let info = child.query_info("standard::name,standard::type,standard::size", 0, null);
+assertEquals(info.get_size(), 12);
+
+print("test-core complete");